<template>
  <div class="app-container">
    <div class="filter-container">
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        查询
      </el-button>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column
        type="index"
        width="50"
      />
      <el-table-column
        prop="username"
        label="账号"
        width="100"
      />
      <el-table-column
        prop="realName"
        label="姓名"
        width="100"
      />
      <el-table-column
        prop="mobile"
        label="手机号"
        width="100"
      />
      <el-table-column align="center" label="操作" min-width="150">
        <template slot-scope="scope">
          <el-button
            v-if="isP('MonitorOnlineOut')"
            style="margin-left: 10px"
            type="primary"
            size="mini"
            @click="handleLogout(scope.row)"
          >强制下线
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="listSysOnline"
    />
  </div>
</template>

<script>
import { listMonitorOnline, logout } from '@/api/monitor/online'
import Pagination from '@/components/Pagination/index'
import msgUtil from '@/utils/msgUtil'

export default {
  components: { Pagination },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20
      }
    }
  },
  created() {
    this.listMonitorOnline()
  },
  methods: {
    listMonitorOnline() {
      this.listLoading = true
      listMonitorOnline(this.listQuery).then(response => {
        this.list = response.data.data
        // this.total = response.data.total
        setTimeout(() => {
          this.listLoading = false
        }, 100)
      })
    },
    // 按钮查询
    handleFilter() {
      this.listQuery.page = 1
      this.listMonitorOnline()
    },
    // 强制下线
    async handleLogout(row) {
      msgUtil.confirm('确认该用户强制下线?').then(async() => {
        await logout({ username: row.username })
        msgUtil.success2('处理成功!')
        this.listMonitorOnline()
      })
    }
  }
}
</script>
